from django.shortcuts import render,HttpResponse
# from jinja2 import Template
# t = Template(文件字符串)
# t.render({''})
# Create your views here.
# 视图  (视图函数,视图类)

# def application(envrion)
#     envrion['PATH_INFO']

def home(request):  #request -- 请求相关信息对象

    print(request.path)  # -- /home/

    # return HttpResponse('陈硕大帅比!')
    return render(request,'home.html')  #模板渲染 模板就是html页面 渲染就是字符串替换
    #第一个参数:request  第二个参数是html页面路径,





def login(request):
    print('当前请求方法:',request.method)
    # if request.method == 'GET':


    print(request.path)

    # return HttpResponse('陈硕大帅比!')
    return render(request,'login.html')
    # else:
    #     # dict
    #     print(request.POST)  #<QueryDict: {'username': ['chao'], 'pwd': ['222']}>
    #     name = request.POST.get('username')  #'chao'
    #     pwd = request.POST.get('pwd')
    #
    #     print(name,pwd) #liye 123
    #     if name=='liye' and pwd == '123':
    #
    #
    #         return HttpResponse('登录成功')
    #     else:
    #         return HttpResponse('登录失败!!')

def login2(request):


    print(request.GET)  # <QueryDict: {'username': ['chao'], 'pwd': ['222']}>
    # name = request.POST.get('username')  # 'chao'
    # pwd = request.POST.get('pwd')

    name = request.GET.get('username')  # 'chao'
    pwd = request.GET.get('pwd')

    print(name, pwd)  # liye 123  cadf 123
    if name == 'liye' and pwd == '123':

        return HttpResponse('登录成功')
    else:
        return HttpResponse('登录失败!!')



#
# def articles(request,year,month):  # 位置参数 2019  9
#     print(year,type(year)) #2019 <class 'str'>  #匹配出来的所有数据都是字符串
#     print(month)
#
#     return HttpResponse(year+'年'+ month +'月' +'所有文章')

def articles(request,oo,xx):  # 关键字传参 2019  9
    print(xx,type(xx)) #2019 <class 'str'>  #匹配出来的所有数据都是字符串
    print(oo)

    return HttpResponse(xx+'年'+ oo +'月' +'所有文章')




